<template>
  <div style="opacity: 0.8">
    <el-card>
      <el-form :inline="true" :model="searchForm">
        <el-form-item label="审批状态">
         <el-select v-model="searchForm.approvalStatus" placeholder="请选择">
          <el-option
            label="待审批"
            value="0">
          </el-option>
          <el-option
            label="审批通过"
            value="1">
          </el-option>
          <el-option
            label="审批未通过"
            value="2">
          </el-option>
        </el-select>
        </el-form-item>
        <el-form-item label="审批类型">
         <el-select v-model="searchForm.approvalType" placeholder="请选择">
          <el-option
            label="会员充值"
            value="0">
          </el-option>
          <el-option
            label="会员消费"
            value="1">
          </el-option>
          <el-option
            label="教练请假"
            value="2">
          </el-option>
          <el-option
            label="购买器材"
            value="3">
          </el-option>
        </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getData()">查询</el-button>
          <!-- <el-button
            @click="openDialog('添加器材信息', { a: '1' })"
            plain
            >添加</el-button
          > -->
        </el-form-item>
      </el-form>
      <!-- 数据列表-->
      <el-table
        :data="tableData"
        border
        class="table"
        ref="multipleTable"
        highlight-current-row
      >
        <el-table-column
          prop="approvalType"
          label="审批类型"
          min-width="160"
        >
          <template slot-scope="scope">
              <span  v-if="scope.row.approvalType == '0'">会员充值</span>
              <span  v-if="scope.row.approvalType == '1'">会员消费</span>
              <span v-if="scope.row.approvalType == '2'">教练请假</span>
              <span v-if="scope.row.approvalType == '3'">购买器材</span>
          </template>
        </el-table-column>
       <el-table-column
          prop="applyName"
          label="申请人"
          min-width="140"
        ></el-table-column>
        <el-table-column
          prop="content"
          label="审批内容"
          min-width="140"
        ></el-table-column>
        <el-table-column
          prop="approvalStatus"
          label="审批状态"
          min-width="160"
        >
          <template slot-scope="scope">
              <span style="color:red" v-if="scope.row.approvalStatus == '2'">审批未通过</span>
              <span style="color:green" v-if="scope.row.approvalStatus == '1'">审批通过</span>
              <span style="color:blue" v-if="scope.row.approvalStatus == '0'">未审批</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="approvalStartDate"
          label="发起审批时间"
          min-width="140"
        ></el-table-column>
        <el-table-column
          prop="approvalEndDate"
          label="审批结束时间"
          min-width="140"
        ></el-table-column>
        <el-table-column
          prop="remarks"
          label="审批意见"
          min-width="140"
        ></el-table-column>
        <el-table-column
          v-if="userInfo.type==='2'"
          label="操作"
          min-width="150"
          align="center"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.approvalStatus==='0'"
              type="text"
              icon="el-icon-edit"
              @click="openDialog('编辑审批信息', scope.row)"
              style="margin-right: 5px;color:yellow"
              >审批
            </el-button>
            <el-popconfirm
              confirm-button-text="确定"
              cancel-button-text="取消"
              icon="el-icon-info"
              @confirm="deleteInfo(scope.row)"
              icon-color="red"
              title="确定删除该审批信息吗？"
            >
              <el-button
                type="text"
                slot="reference"
                icon="el-icon-delete"
                class="red"
                style="color:red"
                >删除
              </el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="pageSizes"
          :page-size="PageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.length"
        >
        </el-pagination>
      </div>
      <!--添加/修改 模态框-->
      <el-dialog
        :title="dialogTitle"
        :visible.sync="dialogFormVisible"
        width="500px"
      >
        <el-form
          :model="editApprovalForm"
          ref="editApprovalForm"
          label-width="120px"
          :inline="true"
        >
          <el-form-item label="审批状态">
         <el-select v-model="editApprovalForm.approvalStatus" placeholder="请选择">
          <el-option
            label="待审批"
            value="0">
          </el-option>
          <el-option
            label="审批通过"
            value="1">
          </el-option>
          <el-option
            label="审批未通过"
            value="2">
          </el-option>
        </el-select>
        </el-form-item>
        <el-form-item label="审批意见:">
            <el-input v-model="editApprovalForm.remarks"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button
            @click="saveEdit"
            v-if="dialogTitle === '编辑审批信息'"
            >保 存</el-button
          >
        </div>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import webservice from "../../utils/webservice";
export default {
  data() {
    return {
      searchForm: {},
      tableData: [],
      dialogFormVisible: false, //添加编辑的模态框标识
      editApprovalForm: {
       
      }, //编辑信息的表单
      // 默认显示第几页
      currentPage: 1,
      // 个数选择器（可修改）
      pageSizes: [1, 5, 10, 20],
      // 默认每页显示的条数（可修改）
      PageSize: 5,
      dialogTitle: "", //模态框标题
      userInfo:{}
    };
  },
  mounted() {
    
    this.userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
    this.getData();
  },
  methods: {
    // 分页
    // 每页显示的条数
    handleSizeChange(val) {
      // 改变每页显示的条数
      this.PageSize = val;
      console.log(this.pageSizes);
      // 注意：在改变每页显示的条数时，要将页码显示到第一页
      this.currentPage = 1;
    },
    // 显示第几页
    handleCurrentChange(val) {
      // 改变默认的页数
      this.currentPage = val;
    },
    //获取信息
    getData() {
      if(this.userInfo.type==='0'){
        var _param = {
        approvalStatus: this.searchForm.approvalStatus,
        approvalType: this.searchForm.approvalType,
        applyId:this.userInfo.id
        };
      }else{
        var _param = {
        approvalStatus: this.searchForm.approvalStatus,
        approvalType: this.searchForm.approvalType,
      };
      }
      
      const params = JSON.stringify(_param)
      webservice.HttpPost("/api/approvalRecord/selectApprovalRecordInfoList", params, (data) => {
        if (data.code === 200) {
          this.tableData = data.data;
        } else {
          this.$message.error({
            message: data.message,
            showClose: true,
            duration: 1000,
          });
        }
      });
    },
    //保存编辑
    saveEdit() {
      let _param = {
        id: this.editApprovalForm.id,
        approvalStatus: this.editApprovalForm.approvalStatus,
        remarks: this.editApprovalForm.remarks,
      };
       const params = JSON.stringify(_param)
      webservice.HttpPost("/api/approvalRecord/updateApprovalRecordInfo", params, (data) => {
        if (data.code === 200) {
          this.dialogFormVisible = false;
          this.getData();
          this.$message.success({
            message: "保存成功！",
            showClose: true,
            duration: 1000,
          });
        } else {
          this.$message.error({
            message: data.message,
            showClose: true,
            duration: 1000,
          });
        }
      });
    },
    //打开添加/编辑 模态框
    openDialog(flag, row) {
      this.dialogTitle = flag;
      if (flag === "编辑审批信息") {
        this.editApprovalForm = JSON.parse(JSON.stringify(row));
      } else {
        this.editApprovalForm = {
          
        };
      }
      this.dialogFormVisible = true;
    },
    //删除
    deleteInfo(row) {
      let _param = {
        id: row.id,
      };
      const params = JSON.stringify(_param)
      webservice.HttpPost("/api/approvalRecord/deleteApprovalRecordInfo", params, (data) => {
        if (data.code === 200) {
          this.getData();
          this.$message.success({
            message: "删除成功！",
            showClose: true,
            duration: 1000,
          });
        } else {
          this.$message.error({
            message: data.message,
            showClose: true,
            duration: 1000,
          });
        }
      });
    },
  },
};
</script>

<style>
</style>